const app = getApp()
Page({
    data: {
        // 点击谁 谁就显红 - 属性绑定好像这个不支持
        categories: [
            '全部', '进行中', '写游记', '已完成'
        ],
        // 活动进度 1-进行中 2-写游记 3-已完成
        schedule_src: [
            '/images/activities/doing.png',
            '/images/activities/over.png',
            '/images/activities/over.png',
        ],
        eleColor: ['red', 'black', 'black', 'black'],
        activities: [],
        activitiesToShow: [],

    },
    onLoad() {
        this.getMyData()
    },
    getMyData() {
        let activities = app.globalData.user.activities
        this.setData({
            activities,
            activitiesToShow: activities
        })
    },
    click(e) {
        // console.log(e);
        let index = e.currentTarget.dataset.index
        let activitiesToShow = []
        let eleColor
        // console.log(index);
        if (index == 0) {
            this.data.activities.forEach(item => {
                activitiesToShow.push(item)
            });
            eleColor = ['red', 'black', 'black', 'black']
        } else if (index == 1) {
            this.data.activities.forEach(item => {
                if (item.schedule == 1) {
                    activitiesToShow.push(item)
                }
            });
            eleColor = ['black', 'red', 'black', 'black']
        } else if (index == 2) {
            this.data.activities.forEach(item => {
                if (item.schedule == 2) {
                    activitiesToShow.push(item)
                }
            });
            eleColor = ['black', 'black', 'red', 'black']
        } else if (index == 3) {
            this.data.activities.forEach(item => {
                if (item.schedule == 3) {
                    activitiesToShow.push(item)
                }
            });
            eleColor = ['black', 'black', 'black', 'red']
        }
        this.setData({
            activitiesToShow,
            eleColor,
        })
    },
    toDetail(e) {
        const schedule = e.currentTarget.dataset.schedule
        // 设置要展示的数据 - 让查看我的参与的页面能拿到数据
        const index = e.currentTarget.dataset.index
        app.setmyParActShowing(this.data.activitiesToShow[index])
        if (schedule == 1) { // 进行中 - 查看
            swan.navigateTo({
                url: "../participation/participation"
            })
        } else if (schedule == 2) { // 写游记
            swan.navigateTo({
                url: "../../messages_pages/publish/publish"
            })
        } else if (schedule == 3) { // 已完成 - 查看
            swan.navigateTo({
                url: "../participation/participation"
            })
        }
    },

});